#pragma once

#include "Common.h"

#define PIN_POT_LEFT A2
#define PIN_POT_RIGHT A3

class HeadPots 
{

public:

  inline static void Init() 
  {
    NextCheckTimeInMs = 0;
  }

  inline static void UpdateNextCheckTime() 
  {
    NextCheckTimeInMs = globals::CurrentLoopTimeInMs + 100;
  }

  inline static bool IsCheckTimeReached() 
  {
    return (NextCheckTimeInMs < globals::CurrentLoopTimeInMs);
  }

  inline static void DoUpdateState() 
  {
    byte new_state;

    new_state = map(analogRead(PIN_POT_LEFT),0,1023,0,127);
    if ( PotLeftValue - new_state ) {
      IsStateChanged = true;
      PotLeftValue = new_state;
    }

    new_state = map((analogRead(PIN_POT_RIGHT)-1023)*-1,0,1023,0,127);
    if ( PotRightValue != new_state ) {
      IsStateChanged = true;
      PotRightValue = new_state;
    }
  }

  inline static void UpdateState() 
  {
    if ( IsCheckTimeReached() ) {
      DoUpdateState();
      UpdateNextCheckTime(); 
    }
  }

  static unsigned long NextCheckTimeInMs;  
  static byte PotLeftValue;
  static byte PotRightValue;
  static bool IsStateChanged;
};




